<script lang="ts" setup name="ndeReportReviewRecord">
import { getListByConditionsWithPage, urls } from '@/index';
import type {
  DialogModel,
  NdeReportReviewRecord,
  NdeReportReviewRecordQueryCondition
} from '@/index.d';
import { useRequest } from 'vue-request';
import DetailDialog from './DetailDialog.vue';
import router from '@/router';
const title = '无损报告审核记录';
const queryCondition = reactive<NdeReportReviewRecordQueryCondition>({
  deleted: false,
  change: false,
  currentPage: 1,
  pageSize: 20,
  isClosed: false,
  isClosedOption: '全部'
});

const resetQueryCondition = () => {
  queryCondition.currentPage = 1;
  queryCondition.pageSize = 20;
  queryCondition.deleted = false;
  delete queryCondition.reportReference;
  delete queryCondition.method;
  delete queryCondition.comment;
  delete queryCondition.commentType;
  delete queryCondition.isClosed;
  delete queryCondition.creatorId;
  queryCondition.isClosedOption = '全部';
};

const {
  data: getNdeReportReviewRecordListData,
  run: getNdeReportReviewRecordListRun,
  loading: getNdeReportReviewRecordListLoading
} = useRequest(() => getListByConditionsWithPage(urls.ndeReportReviewRecord, queryCondition));

const handleResetQuery = () => {
  resetQueryCondition();
  getNdeReportReviewRecordListRun();
};

const detailDialogModel = reactive<DialogModel<NdeReportReviewRecord>>({
  visible: false,
  title,
  type: 'view',
  id: 0,
  change: false
});

watch(
  () => detailDialogModel.visible,
  (value: boolean) => {
    if (!value && detailDialogModel.change) {
      getNdeReportReviewRecordListRun();
      detailDialogModel.change = false;
    }
  }
);
const viewAnalysis = () => {
  router.push('/ndeReport/reviewRecordAnalysis');
};
</script>
<template>
  <HqContainerTable
    :base-url="urls.ndeReportReviewRecord"
    :title="title"
    :loading="getNdeReportReviewRecordListLoading"
    :total="getNdeReportReviewRecordListData?.total"
    :table-data="getNdeReportReviewRecordListData?.records"
    v-model:pageSize="queryCondition.pageSize"
    v-model:current-page="queryCondition.currentPage"
    @handle-query="getNdeReportReviewRecordListRun"
    @handle-reset-query="handleResetQuery"
    @handle-reload="getNdeReportReviewRecordListRun"
    v-model:detail-dialog-model="detailDialogModel"
    :operate-column="true"
  >
    <template #search>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.method"
          clearable
          placeholder="请选择方法"
          @change="getNdeReportReviewRecordListRun"
        >
          <HqNdeMethodOptions />
        </el-select>
      </hq-col>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.creatorId"
          clearable
          placeholder="请选择审核人员"
          @change="getNdeReportReviewRecordListRun"
        >
          <HqUserIdOptions />
        </el-select>
      </hq-col>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.commentType"
          clearable
          placeholder="请选择意见类型"
          @change="getNdeReportReviewRecordListRun"
        >
          <el-option key="委托错误" label="委托错误" value="委托错误" />
          <el-option key="违反规程" label="违反规程" value="违反规程" />
          <el-option key="缺陷描述" label="缺陷描述" value="缺陷描述" />
          <el-option key="其它原因" label="其它原因" value="其它原因" />
        </el-select>
      </hq-col>
      <hq-col kind="search">
        <el-input v-model="queryCondition.comment" placeholder="请输入审核意见关键词" clearable />
      </hq-col>
      <!-- <hq-col kind="search">
        <el-radio-group
          v-model="queryCondition.isClosedOption"
          @change="getNdeReportReviewRecordListRun"
        >
          <el-radio-button label="全部" value="全部" />
          <el-radio-button label="已关闭" value="已关闭" />
          <el-radio-button label="未关闭" value="未关闭" />
        </el-radio-group>
      </hq-col> -->
    </template>

    <template #button>
      <el-button type="primary" @click="viewAnalysis">查看分析</el-button>
    </template>

    <template #tableColumns>
      <HqTableColumn label="报告编号" :min-width="150">
        <template #default="{ row }">
          <el-link
            type="success"
            v-if="row.reportAttachmentUrl"
            :href="row.reportAttachmentUrl"
            target="_blank"
          >
            {{ row.reportReference }}
          </el-link>
          <el-text v-else> {{ row.reportReference }} </el-text>
        </template>
      </HqTableColumn>
      <HqTableColumn label="检测方法" prop="method" :min-width="50" />
      <HqTableColumn label="编制人员" prop="reportPrepareByUser.name" :min-width="50" />
      <HqTableColumn label="审核人员" prop="creator.name" :min-width="50" />
      <HqTableColumn label="审核时间" prop="createTime" :min-width="100" />
      <HqTableColumn label="通知总次数" prop="noticeTimes" :min-width="60" />
      <HqTableColumn label="最近通知次数" prop="noticeTimesRecent" :min-width="60" />
      <HqTableColumn label="最近通知时间" prop="lastNoticeTime" :min-width="100" />
      <HqTableColumn label="意见类型" prop="commentType" :min-width="60" />
      <HqTableColumn label="意见详情" prop="comment" :min-width="400" />
      <!-- <HqTableColumn label="是否关闭" :min-width="100">
        <template #default="{ row }">
          <el-switch
            v-model="row.isClosed"
            class="mb-2"
            active-text="已关闭"
            inactive-text="未关闭"
            :disabled="!isLoginUserById(row.creator.id)"
          />
        </template>
      </HqTableColumn> -->
    </template>
  </HqContainerTable>
  <DetailDialog v-model:dialog-model="detailDialogModel" v-if="detailDialogModel.visible" />
</template>
<style lang="scss" scoped></style>
